export default {
    methods: {
        /**
         *跳转到
        *@param path
        */
        goTo: function (path) {
            this.$router.push({
            name: path
            });
        },
        goToParams: function (name, params) {
            this.$router.push({
            name: name,
            params: params || {}
            });
        },
        goToQuery: function (name, params) {
            this.$router.push({
            name: name,
            query: params || {}
            });
        },

         //验证手机
        checkPnoneNum: function (rule, value, callback) {
            if (!value) {
                return callback(new Error("电话不能为空"));
                } else {
                var reg1 = /^\d+$/g;
                if (!reg1.test(value)) {
                    callback(new Error("请输入数字"));
                } else {
                    var reg2 = /^1(3|4|5|6|7|8|9)\d{9}$/g;
                    if (!reg2.test(value)) {
                    callback(new Error("请输入正确格式的电话号码"));
                    } else {
                    callback();
                    }
                }
            }
        },

      
        //获取url query值
        getQueryString: function (name) {
            const url = window.location.href;
            if (url.indexOf(name) === -1) {
                return ""
            }
            const after = window.location.search.substr[1] || window.location.hash.split("?")[1]
            if (!after) {
                return ""
            }
            const reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
            const r = after.match(reg);
            if (r != null) {
            return unescape(r[2]);
            }
            return "";
        },

        //获取访问记录信息
       accessRecord: function (viewId,state) { 
            let umsId = ''
            let source = '02'
            if(state == 'url') {
                umsId = this.getQueryString('umsId') || ''
                source = this.getQueryString('accessSource') || '01'
                this.$storage.set('taxDiscountSource', {source:source})
                //缓存访问信息
                if(umsId) {
                    this.$storage.add('taxDiscountSource','umsId',umsId)
                }
            }else{
                if(this.$storage.get('taxDiscountSource')) {
                    umsId = this.$storage.get('taxDiscountSource').umsId || ''
                    source = this.$storage.get('taxDiscountSource').source || '01'
                }
            }
            const data = {
                accessSource: source,
                viewId: viewId,
                userId: umsId
            }
            this.$axios
            .post(this.API.accessRecord,data)
            .then(res => {
                if(res.data.code == 100) {
                
                }else{
                    // this.$message.error(res.data.mesg)
                }
            })
            .catch(err => {
            // console.log(err);
            });
        },

        //推出查询
        quitQuery() {
            this.goTo('Home')
            this.$storage.remove('taxDiscount')
            this.$storage.remove('taxDiscountSource')
        },


    }
}